<?php
/**
 * licenses : MIT
 * creatTime: 2020/5/15
 * author : weblinuxgame
 * filename: Captcha.php
 */

namespace App\Core\Rules;

use App\Services\CaptchaStorageService;
use Illuminate\Contracts\Validation\ImplicitRule;

/**
 * 验证验证是否通过
 * Class Captcha
 * @package App\Core\Rules
 */
class CaptchaRule implements ImplicitRule
{
    /**
     * 确定验证规则是否通过。
     *
     * @param string $attribute
     * @param mixed $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $key = request("_" . $attribute, '');
        return CaptchaStorageService::getInstance()->verify($value, $key);
    }

    /**
     * 获取验证错误消息。
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute not match.';
    }

}
